package com.project.erp.service.system.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.project.erp.common.utils.Page;
import com.project.erp.dao.system.PostsDao;
import com.project.erp.model.system.Posts;
import com.project.erp.service.system.PostsService;

@Service
@Transactional
public class PostsServiceImpl implements PostsService {
	
	@Autowired
	private PostsDao postsDao;
	
	//只读事务，可以提高效率
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	@Override
	public Page<Posts> getPostsPageBySearch(Page<Posts> page, Posts posts) {
		return postsDao.getPostsPageBySearch(page, posts);
	}

	@Transactional(rollbackFor=Exception.class)
	@Override
	public void savePosts(Posts posts) {
		postsDao.save(posts);
	}
	
	//只读事务，可以提高效率
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	@Override
	public Posts getPostsById(Long postsId) {
		return postsDao.get(postsId);
	}

	@Transactional(rollbackFor=Exception.class)
	@Override
	public void editPosts(Posts posts) {
		postsDao.save(posts);
	}

	@Transactional(rollbackFor=Exception.class)
	@Override
	public void delPosts(String[] postsIds) {
		if(null == postsIds || postsIds.length == 0){
			return;
		}
		List<Long> ids = new ArrayList<Long>();
		for (String postsId : postsIds) {
			ids.add(Long.valueOf(postsId));
		}
		//删除主表信息
		postsDao.deleteByIdsList(ids);
	}

	@Override
	public Map<String, Map<String, String>> getAllPostss() {
		
		return null;
	}

	//只读事务，可以提高效率
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	@Override
	public Posts getPostsByPostNum(String postNum) {
		return postsDao.getPostsByPostNum(postNum);
	}

}
